package com.guxingke.gblog.controller.back;

import java.util.Date;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.guxingke.gblog.controller.BaseController;
import com.guxingke.gblog.dmo.Article;
import com.guxingke.gblog.dto.AboutDto;

@Controller
@RequestMapping("/manage/about")
public class AboutManageController extends BaseController {

	@RequestMapping
	public ModelAndView detail(HttpSession session) {
		ModelAndView mav = new ModelAndView();

		AboutDto about = articleService.getAbout();

		if (about == null) {
			Article article = new Article();
			article.setCategoryId(0);
			article.setClicks(0);
			article.setContent("待续…………");
			article.setIsDraft(0);
			article.setPicture("default.jpg");
			article.setPubDate(new Date());
			article.setRemark("about");
			article.setTitle("about");
			article.setUserId(1);
			articleService.saveArticle(article);
		}

		mav.addObject("about", about);
		mav.addObject("mainPage", "about/manage-detail.jsp");

		mav.setViewName("manage");
		return mav;
	}

	@RequestMapping("/edit")
	public ModelAndView edit() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("about", articleService.getAbout());

		mav.addObject("mainPage", "about/manage-save.jsp");

		mav.setViewName("manage");
		return mav;
	}

	@RequestMapping("/save")
	public String save(AboutDto about) {
		articleService.saveAbout(about);
		return "redirect:/manage/about.do";
	}
}
